"""处理时间格式的函数"""
def sanitize(time_string):
    if "-" in time_string:
        spliter = "-"
    elif ":" in time_string:
        spliter = ":"
    else:
        return time_string
    (mins, secs) = time_string.split(spliter)
    return mins + '.' + secs


"""读取文件内容"""
def get_file_data(filename):
    try:
        with open(filename) as files:
            data = files.readline()
            temp_list = data.strip().split(",")
            return {'Name': temp_list.pop(0),
                    'Dob': temp_list.pop(0),
                    'Times': sorted(set([sanitize(t) for t in temp_list]), reverse=True)[0:3]}
    except IOError as err:
        print("File Error" + err)


james = get_file_data("F:/data/file7/james.txt")
julie = get_file_data("F:/data/file7/julie.txt")
mikey = get_file_data("F:/data/file7/mikey.txt")
sarah = get_file_data("F:/data/file7/sarah.txt")
print(james['Name'] + " fast times is :" + str(james['Times']))
print(julie['Name'] + " fast times is :" + str(julie['Times']))
print(mikey['Name'] + " fast times is :" + str(mikey['Times']))
print(sarah['Name'] + " fast times is :" + str(sarah['Times']))
